package com.siteseat.common.misc;

/**
 *
 */
public enum SizeUnit {
  BIT {
    @Override
    public double toBit( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toBit( s );
    }

    @Override
    public double toByte( long s ) {
      return s / 8.0f;
    }
  },
  BYTE {
    @Override
    public double toByte( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toByte( s );
    }
  },
  KB {
    @Override
    public double toKB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toKB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024;
    }
  },
  MB {
    @Override
    public double toMB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toMB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024;
    }
  },
  GB {
    @Override
    public double toGB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toGB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024 * 1024;
    }
  },
  TB {
    @Override
    public double toTB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toTB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024 * 1024 * 1024;
    }
  },
  PB {
    @Override
    public double toPB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toPB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024 * 1024 * 1024 * 1024;
    }
  },
  EB {
    @Override
    public double toEB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toEB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
    }
  },
  ZB {
    @Override
    public double toZB( long s ) {
      return s;
    }

    @Override
    public double convertFrom( long s, SizeUnit u ) {
      return u.toZB( s );
    }

    @Override
    public double toByte( long s ) {
      return s * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024;
    }
  };

  public abstract double convertFrom( long s, SizeUnit u );

  public double toBit( long s ) {
    return toByte( s ) * 8;
  }

  public abstract double toByte( long s );

  public double toKB( long s ) {
    return toByte( s ) / 1024;
  }

  public double toMB( long s ) {
    return toKB( s ) / 1024;
  }

  public double toGB( long s ) {
    return toMB( s ) / 1024;
  }

  public double toTB( long s ) {
    return toGB( s ) / 1024;
  }

  public double toPB( long s ) {
    return toTB( s ) / 1024;
  }

  public double toEB( long s ) {
    return toPB( s ) / 1024;
  }

  public double toZB( long s ) {
    return toEB( s ) / 1024;
  }
}
